package com.tuanzi.loan.business.service.statistics.impl;

import com.tuanzi.loan.business.entity.statistics.StatNotRegisterLogin;
import com.tuanzi.loan.business.repository.statistics.StatNotRegisterLoginRepository;
import com.tuanzi.loan.business.service.statistics.StatNotRegisterLoginService;
import com.tuanzi.loan.core.aspect.Debug;
import com.tuanzi.loan.core.service.CommonServiceImpl;
import com.tuanzi.loan.core.vo.PageSearcher;
import com.tuanzi.loan.vo.request.statistics.StatNotRegisterLoginRequest;
import com.tuanzi.loan.vo.response.statistics.StatNotRegisterLoginResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.retry.RetryException;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * User: liangZongXi
 * Create time: 15:05 2019/10/9
 * Description:
 */
@Debug
@Service
@Transactional
@Retryable(value = { RetryException.class })
public class StatNotRegisterLoginServiceImpl extends CommonServiceImpl<StatNotRegisterLogin, Long> implements StatNotRegisterLoginService {

    @Autowired
    private StatNotRegisterLoginRepository statNotRegisterLoginRepository;

    @Override
    public Page<StatNotRegisterLoginResponse> list(PageSearcher<StatNotRegisterLoginRequest> pageSearcher) {
        return statNotRegisterLoginRepository.list(pageSearcher.getSearchCondition(), pageSearcher.getPageable());
    }

    @Override
    public void statYesterdayNotRegisterLogin() {
        List<StatNotRegisterLogin> yesterdayNotRegisterLogin = statNotRegisterLoginRepository.findYesterdayNotRegisterLogin();
        if(null != yesterdayNotRegisterLogin && yesterdayNotRegisterLogin.size() > 0){
            this.saveOrUpdate(yesterdayNotRegisterLogin);
        }
    }

    @Override
    protected JpaRepository<StatNotRegisterLogin, Long> getRepository() {
        return statNotRegisterLoginRepository;
    }
}
